#include "SetModeCommand.h"
#include <GraphicsScene.h>

SetModeCommand::SetModeCommand(GraphicsBoxItem* item,
	BaseCommand* stretchCommand, BoxGraphicsMode oldMode, BoxGraphicsMode newMode)
	: m_boxItem(item)
	, m_stretchCommand(stretchCommand)
	, m_oldMode(oldMode)
	, m_newMode(newMode)
{

}


void SetModeCommand::undo()
{
	if (!m_boxItem)
		return;
	m_stretchCommand->undo();
	setMode(m_oldMode);
	m_boxItem->setImageSelected();
	emit m_boxItem->sigModeChanged(m_oldMode);
}

void SetModeCommand::redo()
{
	m_stretchCommand->redo();
	if (m_isFirstPush) {
		m_isFirstPush = false;
		return;
	}
	if (!m_boxItem)
		return;
	setMode(m_newMode);
	m_boxItem->setImageSelected();
	emit m_boxItem->sigModeChanged(m_newMode);
}

void SetModeCommand::setMode(BoxGraphicsMode mode)
{
	switch (mode)
	{
	case BoxGraphicsMode::FIX_1_1_Enum:
	{
		m_boxItem->getItemData().setItemMode(GraphicsItemMode::Fix_Enum, 1.0);
	}
	break;
	case BoxGraphicsMode::FIX_3_4_Enum:
	{
		m_boxItem->getItemData().setItemMode(GraphicsItemMode::Fix_Enum, 3.0 / 4.0);
	}
	break;
	case BoxGraphicsMode::FIX_4_3_Enum:
	{
		m_boxItem->getItemData().setItemMode(GraphicsItemMode::Fix_Enum, 4.0 / 3.0);
	}
	break;
	case BoxGraphicsMode::FIX_16_9_Enum:
	{
		m_boxItem->getItemData().setItemMode(GraphicsItemMode::Fix_Enum, 16.0 / 9.0);
	}
	break;
	case BoxGraphicsMode::FIX_9_16_Enum:
	{
		m_boxItem->getItemData().setItemMode(GraphicsItemMode::Fix_Enum, 9.0 / 16.0);
	}
	break;
	case BoxGraphicsMode::FREE_Enum:
	{
		m_boxItem->getItemData().setItemMode(GraphicsItemMode::Free_Enum, 1);
	}
	break;
	default:
		break;
	}
}
